﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Happy.Archetype;
using Happy.Domain;
using Happy.Utils.Encryption;

namespace Happy.Security.Domain.Users
{
    [DomainService]
    public sealed class PasswordService : DomainService<User, Guid, IUserRepository>
    {
        public bool CheckPassword(User user, string password)
        {
            return user.Password == Encrypte(password);
        }

        public void ChangePassword(User user, string password)
        {
            if (String.IsNullOrEmpty(password))
            {
                return;
            }

            user.ChangePassword(Encrypte(password));
        }

        internal static string Encrypte(string password)
        {
            return HashUtil.MD5(password);
        }
    }
}
